package cn.edu.cug.cs.gtl.apis.ui.datake.devicetree;


import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreeNodeEditor;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreeNodeRenderer;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreePanel;

import javax.swing.*;
import java.awt.*;

public class DevicePanel extends TreePanel {
    public DevicePanel(AbstractApplication theApp, LayoutManager layout, boolean isDoubleBuffered) {
        super(theApp, layout, isDoubleBuffered);
    }

    public DevicePanel(AbstractApplication theApp, LayoutManager layout) {
        super(theApp, layout);
    }

    public DevicePanel(AbstractApplication theApp, boolean isDoubleBuffered) {
        super(theApp, isDoubleBuffered);
    }

    public DevicePanel(AbstractApplication theApp) {
        super(theApp);
    }

    @Override
    public void initial() {

        treeComponent = DeviceTree.create(theApp);

        DeviceTreeTool.loadDevice(treeComponent);

        final TreeNodeRenderer renderer = new TreeNodeRenderer();
        treeComponent.setCellRenderer(renderer);

        final TreeNodeEditor editor = new TreeNodeEditor(treeComponent);
        treeComponent.setCellEditor(editor);
        treeComponent.setEditable(true);

        treeComponent.addTreeSelectionListener(new DeviceTreeSelectionListener(treeComponent,this.theApp));
        treeComponent.getModel().addTreeModelListener(new DeviceTreeModelListener(treeComponent,this.theApp));
        treeComponent.addMouseListener(new DeviceTreeMouseListener(treeComponent,this.theApp));

        scrollPane = new JScrollPane(treeComponent);
        add(scrollPane, BorderLayout.CENTER);
    }

    @Override
    public void reset(Object o) {

    }


}
